<!DOCTYPE html>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>员工管理</title>
<script src="js/global1.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
	var uuid=null;
	var uusid=null;
	var uroid=null;
	var uid=null;
	var tt14=null;
	var tt15=null;
	var tt16=null;
	var tt17=null;
	var tt18=null;
	var tt19=null;
	var tt20=null;
	var tt21=null;
	$(function() {
		init();
	})
	function mokuai(){
				
				var rid=$("#rrrid").val();
				$.post(globalData.pre+"/MyModules",{
					rid:rid
				},function(res){
					   tt=res; 
					  for ( i in tt){  
						  
						  if (tt[i].mid==14) {
								$("#zengjiaadd" ).css("display", "block"); 
							}
						if (tt[i].mid==15) {
							tt15=tt[i].mid; 
						}
						if (tt[i].mid==16) {
							tt16=tt[i].mid; 
						}
						if (tt[i].mid==17) {
							tt17=tt[i].mid; 
						}
						
						if (tt[i].mid==18) {
							tt18=tt[i].mid;  
						}
						if (tt[i].mid==19) {
							tt19=tt[i].mid; 
							$("#quanqiantui" ).css("display", "block"); 
						}
						if (tt[i].mid==20) {
							tt20=tt[i].mid;  
						}
						if (tt[i].mid==21) {
							tt21=tt[i].mid; 
						}
				 }
				},"json")
				
				
				
			}
	function init() {
		$("#zengjiaadd" ).css("display", "none"); 
		mokuai();
		
		$("#tabemp").datagrid({
			url : globalData.pre+"/selectUser",
			method : "post",
			pagination : true,
			toolbar : '#bar',
			queryParams : {
				uname : $("#uname").val(),
				ulock : $("#ulock").combobox("getValue"),
				umax : $("#umax").datetimebox("getValue"),
				umin : $("#umin").datetimebox("getValue"),
				genju : $("#genju").combobox("getValue"),
				zheng : $("#zheng").combobox("getValue"),
				usign : $("#usign").combobox("getValue"),
				kaishishijian:$("#kaishishijian").datetimebox("getValue"),
				jieshushijian:$("#jieshushijian").datetimebox("getValue")
			}
		});
		$("#barfrm").form("reset");
	}

	
	function formatterjiesuojuese(value,row,index){
		
		if (tt17==17) {
			if(row.ulock==2){
				return '<a  href="javascript:void(0)" onclick="juese(' + index+","+1 + ')">解锁角色</a>'
			}else{
				return '<a  href="javascript:void(0)" onclick="juese(' + index+","+2 + ')">锁定角色</a>'			
			}
		}else{
			return "未授权"
		}
	}
	function formattershezhijuese(value,row,index){
		if (tt18==18) {
			return '<a  href="javascript:void(0)" onclick="userroles(' + index + ')">设置角色</a>'			
		}else{
			return "未授权"
		}
	}
	function formatterquanzhong(value,row,index){
		if (tt19==19) {
			return '<a  href="javascript:void(0)" onclick="quan(' + index + ')">设置权重</a>'
		}else{
			return "未授权"
		}
	}
	function formatterxiugai(value,row,index){
		if (tt16==16) {
			return ' <a  href="javascript:void(0)" onclick="updateUser(' + index + ')">修改</a>'			
		}else{
			return "未授权"
		}
	}
	function formattersanchu(value,row,index){
		if (tt15==15) {
			return '<a  href="javascript:void(0)" onclick="del(' + index + ')">删除</a>'
		}else{
			return "未授权"
		}
	}
	function formatterchongzhimima(value,row,index){
		if (tt20==20) {
			return ' <a  href="javascript:void(0)" onclick="chongzhiq(' + index + ')">重置密码</a>'			
		}else{
			return "未授权"
		}
	}
	function formatterqiantui(value,row,index){
		if (tt21==21) {
			return '     <a  href="javascript:void(0)" onclick="qiandaoq(' + index + ')">签退</a>'
		}else{
			return "未授权"
		}
	}
	
	function chongzhiq(index) {

		var data = $("#tabemp").datagrid("getData");
		var row = data.rows[index];
		$.messager.confirm('确认', '您确认想要重置密码吗？', function(res) {
			$.post(globalData.pre+"/chongzhi", {
				uid : row.uid

			}, function(res) {
				if (res) {
					//重载表格
					$("#tabemp").datagrid("reload");
					$.messager.alert("提示", "重置成功");
				} else {
					$.messager.alert("提示", "重置失败");
				}

			})
		});
		

	}
	/*签到*/
	function qiandaoq(index) {

		var data = $("#tabemp").datagrid("getData");
		var row = data.rows[index];
		if (row.usign != 1) {
			$.post(globalData.pre+"/qiandaoq1", {
				uid : row.uid,
				usign : row.usign

			}, function(res) {
				$.messager.confirm('确认', '您确认想要签到吗？', function(res) {
					if (res) {

						$("#tabemp").datagrid("reload");
						$.messager.alert("提示", "签到成功");
					} else {
						$.messager.alert("提示", "签到失败");
					}
				});

			})
		} else {
			$.messager.alert("提示", "请勿重复签到");

		}

	}
	function juese(index,i){
		var data = $("#tabemp").datagrid("getData");
		var row = data.rows[index];
		$.post(globalData.pre+"/updateUser",{
			uid:row.uid,
			ulock:i,
			upassnum:0
		},function(res){
			if (i==1) {
				alert("解锁成功");
				init();
			} else {
				alert("锁定成功");
				init();
			}
			
			
		},"json")
	}
	
	//打开增加页面
	function openAddwin() {
		$("#addwin").window("open");
	}
	//增加用户
	function addok() {
		//异步传输
		//验证邮箱是否合法（正则表达式）
		var myReg=/^[a-zA-Z0-9_-]+@([a-zA-Z0-9]+\.)+(com|cn|net|org)$/;
		//验证手机号是否合法
		 var partten = /^1[3,5,8]\d{9}$/;
		 //获取表单中的数据
		var uname=$("#uname2").val();
		var umali=$("#umail").val();
		var uphone=$("#uphone").val();
		if(uname!=''&&uname!=null){
			if(myReg.test(umali)){
				if(partten.test(uphone)){
					$.post(globalData.pre+"/indeteUser", {
						//携带的数据
						uname : uname,
						usex : $("#usex").combobox('getValue'),
						uage : $("#uage").val(),
						//初始密码
						upassword : 'ysd123',
						ulock : $("#ulock").val(),
						//密码错误次数
						upassnum : 0,
						umail :umali,
						uphone : uphone,

					}, function(res) {
						if (res == 1) {
							alert("增加成功");
							$('#addwin').window('close');
							//重载表格
							init();
						} else if(res==2){
							alert("用户名已被占用");
						}else{
							alert("增加失败");
							$('#addwin').window('close');
							init();
						}
					}, "json")
				}else{
					$.messager.alert('提示', '手机号不符合格式');
				}
			}else{
				$.messager.alert('提示', '邮箱不符合格式');
			}
		}else{
			$.messager.alert('提示', '姓名不可为空');
		}
		//传输的地址
		
	}

	function addno() {
		$('#addwin').window('close');
	}

	
	/*修改  */
	function updateUser(index) {
		//获取表格的数据
		var data = $("#tabemp").datagrid("getData");
		//根据下标获取点击行的数据
		var row = data.rows[index];
		//把数据加载到form表单里
		$("#updateform").form("load", row);
		//打开修改面板
		$('#updateUser').window('open');
	}
	function quan(index) {
		var data = $("#tabemp").datagrid("getData");
		var row = data.rows[index];
		$("#quanform").form("load", row);
		$('#quanUser').window('open');
	}
	function updOK1() {
		$.post(globalData.pre+"/updateUser", {
			uid:$("#uid11").val(),
			ureserved1 : $("#ureserved11").val(),
			utest : $("#utest1").val(),
			

		}, function(res) {
			if (res > 0) {
				alert("修改成功");
				$('#quanUser').window('close');
				init();
			} else {
				alert("修改失败");
				$('#quanUser').window('close');
			}
		}, "json")
	}
	function upno1() {
		$('#quanUser').window('close');
	}
	function updOK() {
		$.post(globalData.pre+"/updateUser", {
			//获取表单的数据
			uid : $("#uid1").val(),
			usex : $("#usex1").combobox('getValue'),
			uage : $("#uage1").val(),
			umail : $("#umail1").val(),
			uphone : $("#uphone1").val(),
				//返回值
		}, function(res) {
			if (res > 0) {
				alert("修改成功");
				$('#updateUser').window('close');
				init();
			} else {
				alert("修改失败");
				$('#updateUser').window('close');
			}
			//参数类型
		}, "json")
	}

	function upno() {
		$('#updateUser').window('close');
	}
	function del(index) {
		var data = $("#tabemp").datagrid("getData");
		//根据下标获取当前行的数据
		var row = data.rows[index];

		$.messager.confirm('确认', '您确认想要删除这条记录吗？', function(r) {
			if (r) {
				
				$.post(globalData.pre+"/deleteUser", {
					uid : row.uid
				}, function(res) {
					if (res > 0) {
						$.messager.alert('提示', '删除成功');
						init();
					}else if (res==0){
						$.messager.alert('警告', '删除角色失败，请给该用户解除角色后再试一下');
					
					} else {
						$.messager.alert('警告', '删除失败');
					}
				})
			}
		});
	}
	function forusign(value,row,index){
		return value==1?"是":"否";
	}
	
	function forulock(value,row,index){
		return value==2?"是":"否";
	}
	function foruusex(value,row,index){
		return value==2?"女":"男";
	}
	
	
	
	
	function userroles(index){
		var data = $("#tabemp").datagrid("getData");
		var row = data.rows[index];
		$("#xg").form("load", row);
		$("#updatediv").dialog("open");
		uid=row.uid;
		uusid=row.uid;
		initt()
	}
	function initt(){
		$('#cx').datagrid({    
		    url:'selectRoleslist',
		    singleSelect:true,  
		    onSelect: function(indexs,row){
				var data=$("#cx").datagrid("getData");
				uroid=data.rows[indexs].rid
				uuid=row.uuid
	        },
		    columns:[[       
		        {field:'rname',title:'角色名称'} 
		    ]]    
		});  
		$('#zj').datagrid({    
		    url:'myRoleslist',
		    singleSelect:true,
		    queryParams: {
		    	uid: uid,
			},onSelect: function(indexs,row){
				var data=$("#zj").datagrid("getData");
				uroid=data.rows[indexs].rid;
				uuid=data.rows[indexs].uuid
	        },
		    columns:[[        
		        {field:'rname',title:'角色名称'}   
		    ]]    
		}); 
	}
	//给用户增加角色
	function zengjia(){
		$.post(globalData.pre+"/selectUserroles",{
			uusid:uusid,
			uroid:uroid
		},function(res){
			if (res==0) {
				$.post(globalData.pre+"/insertUserroles",{
					uusid:uusid,
					uroid:uroid
				},function(res){
					if (res>0) {
						alert("添加角色成功")
						initt()
					}else{
						alert("添加角色失败，请刷新后再试一下")
						initt()
					}
				},"json")
			}else{
				alert("该用户已经有这个角色了")
			}
		},"json")
		
		
	}
	function sanchu(){
		$.post(globalData.pre+"/deleteUserroles",{
			uuid:uuid
		},function(res){
			if (res>0) {
				alert("删除角色成功")
				initt()
			}else{
				alert("删除角色失败，请刷新后再试一下")
				initt()
			}
		},"json")
	}
	function quanqiantui(){
		$.messager.confirm('确认', '您确认时间未到就全部签退吗？', function(r) {
			if (r) {
				$.post(globalData.pre+"/quanbuqiantui",{},function(res){
					if (res>0) {
						alert("全部签退成功")
						initt()
					}else{
						alert("全部签退失败，请刷新后再试一下")
						initt()
					}
				},"json")
			}
		});
		
	}
</script>
</head>
<body>
	<table id="tabemp" class="easyui-datagrid">
		<thead>
			<tr>
				<th data-options="field:'uid',title:'用户id'"></th>
				<th data-options="field:'uname',title:'用户姓名'"></th>
				<th data-options="field:'usex',title:'性别',formatter:foruusex"></th>
				<th data-options="field:'uage',title:'年龄'"></th>
				<th data-options="field:'usign',title:'已签到',formatter:forusign"></th>
				<th data-options="field:'usigndate',title:'签到时间'"></th>
				<th data-options="field:'upassword',title:'密码'"></th>
				<th data-options="field:'ulock',title:'已锁定',formatter:forulock"></th>
				<th data-options="field:'ulockdate',title:'锁定时间'"></th>
				<th data-options="field:'uenddate',title:'最后登录时间'"></th>
				<th data-options="field:'usetdate',title:'账户创建时间'"></th>
				<th data-options="field:'upassnum',title:'错误次数'"></th>
				<th data-options="field:'umail',title:'邮箱'"></th>
				<th data-options="field:'uphone',title:'手机号'"></th>
				<th data-options="field:'ureserved1',title:'权重'"></th>
		<!-- 		<th data-options="field:'umax',title:'创建起止时间'"></th>
				<th data-options="field:'umin',title:'创建结束时间'"></th> -->
				<th data-options="field:'caozuo',title:'解锁定角色',formatter:formatterjiesuojuese"></th>
				<th data-options="field:'shezhi',title:'设置角色 ',formatter:formattershezhijuese"></th>
				<th data-options="field:'quanzhong',title:'设置权重',formatter:formatterquanzhong"></th>
				<th data-options="field:'xiugai',title:'修改',formatter:formatterxiugai"></th>
				<th data-options="field:'sanchu',title:'删除',formatter:formattersanchu"></th>
				<th data-options="field:'chongzhi',title:'重置密码 ',formatter:formatterchongzhimima"></th>
				<th data-options="field:'qiantui',title:'签退',formatter:formatterqiantui"></th>
			</tr>
		</thead>
	</table>
<input  type="hidden"  id="uidn" name="uidn" value="${list.uid }" />

<input class="easyui-validatebox" type="hidden" value="${list.roles.rid}"  id="rrrid"/>
<div id="updatediv" class="easyui-window" style="width: 350px; height: 400px" title="修改角色" data-options="iconCls:'icon-save',modal:true,closable:true,closed:true">
		<form id="xg">
			<table>
				<tr>
					<td>
						<table style="width: 71px; " id="cx">  </table>  
					</td>
					<td>	
						<a href="javascript:void(0)" style="width: 50px; height: 30px" onclick="zengjia()"class="easyui-linkbutton">--></a>
						<div style="width: 50px; height: 10px"></div>
						<a href="javascript:void(0)" style="width: 50px; height: 30px" onclick="sanchu()"class="easyui-linkbutton"><--</a>
					</td>
					<td>
						<table style="width: 71px; " id="zj">  </table>  
						
					</td>
				</tr>	
			</table>
		</form>
	</div>
	<div id="bar">
		<form id="barfrm" class="easyui-form">
			<label >用户名:</label> 
			<input class="easyui-validatebox" type="text" id="uname" /> 
			<label >创建起止时间:</label>
			<input class="easyui-datetimebox" type="text" id="umax" />  
			<label >创建结束时间:</label> 
			<input class="easyui-datetimebox" type="text" id="umin" />
			<br>
			<label for="name">是否锁定:</label>
			<select id="ulock" class="easyui-combobox"  style="width: 200px;">
					<option value="">请选择</option>
					<option value="2">是</option>
					<option value="1">否</option>
			</select> 
			
			<label >根据:</label>   
	        <select id="genju" class="easyui-combobox"  style="width:150px;"> 
	       		<option value="">---请选择---</option>
			    <option value="usetdate">创建时间</option>   
			    <option value="uenddate">最后登录时间</option>   
			</select>
	        <select id="zheng" class="easyui-combobox"  style="width:50px;"> 
			    <option value="asc">正</option>   
			    <option value="desc">倒</option>   
			</select>
			<label >序:</label>   
			</select> <label for="name">签到状态:</label> <select id=usign
				class="easyui-combobox" name="dept" style="width: 200px;">
				<option value="">---请选择---</option>
				<option value="1">已签到</option>
				<option value="2">未签到</option>
			</select>
			<br>
			<label>签到开始时间:</label> <input class="easyui-datetimebox" type="text"
				id="kaishishijian"  data-options="required:false"/>
				
			<label>签到结束时间:</label> <input class="easyui-datetimebox" type="text"
				id="jieshushijian"  data-options="required:false"/>

			
			<a href="javascript:void(0)" class="easyui-linkbutton" 	onclick="init()" data-options="iconCls:'icon-search'">搜索</a>
			<label><div id="zengjiaadd"><a href="javascript:void(0)" class="easyui-linkbutton" 	onclick="openAddwin()" data-options="iconCls:'icon-add'">增加</a></div>
			<div id="quanqiantui"><a href="javascript:void(0)" class="easyui-linkbutton" 	onclick="quanqiantui()" ">全部签退</a></div>
			</label>
		</form>
	</div>



<!-- 增加面板 -->
	<div id="addwin" class="easyui-window" title="添加用户"
		style="width: 600px; height: 400px"
		data-options="closed:true,modal:true">
		<form id="addform">
			<table>
				
				<tr>
					<td>用户姓名：</td>
					<td><input type="text" class="easyui-textbox" id="uname2" name="uname" /></td>
				</tr>
				
				<tr>
					<td>性别：</td>
					<td>
					<select id="usex" class="easyui-combobox" name="usex" style="width: 173px;">
						
						<option value="1">男</option>
						<option value="2">女</option>
					</select>	
					</td>
						
				</tr>
				<tr>
					<td>年龄:</td>
					<td><input type="text" class="easyui-textbox" id="uage"
						name="uage" /></td>
				</tr>

				
				<tr>
					<td>是否锁定:</td>
					<td>
					<select id="ulock1" class="easyui-combobox" name="ulock1" style="width: 173px;">
						<option value="">请选择</option>
						<option value="1">是</option>
						<option value="2">否</option>
					</select>
					</td>
				</tr>
				

				
				
				<tr>
					<td>邮箱:</td>
					<td><input type="text" class="easyui-textbox" id="umail"
						name="umail" /></td>
				</tr>
				<tr>
					<td>手机号:</td>
					<td><input type="text" class="easyui-textbox" id="uphone"
						name="uphone" /></td>
				</tr>
				


			</table>
			<a type="button" class="easyui-linkbutton" onclick="addok()">确定添加</a>
			<a type="button" class="easyui-linkbutton" onclick="addno()">取消</a>
		</form>
	</div>


	<!--  修改-->
	<div id="updateUser" class="easyui-window" title="修改用户"
		style="width: 600px; height: 400px"
		data-options="title:'编辑窗口',closed:true,modal:true">
		<form id="updateform" class="easyui-form">
			<table>
				<tr>
					<td>用户id：</td>
					<td><input type="text" disabled="disabled" class="easyui-textbox" id="uid1"
						name="uid" /></td>
				</tr>
				<tr>
					<td>用户姓名：</td>
					<td><input type="text"  disabled="disabled" class="easyui-textbox" id="uname1"
						name="uname" /></td>
				</tr>
				<tr>
					<td>性别：</td>
					<td>
					<select id="usex1" class="easyui-combobox" name="usex" style="width: 173px;">
						
						<option value="1">男</option>
						<option value="2">女</option>
					</select>	
					</td>
						
				</tr>
				<tr>
					<td>年龄:</td>
					<td><input type="text" class="easyui-textbox" id="uage1"
						name="uage" /></td>
				</tr>
				
				
				<tr>
					<td>是否锁定:</td>
					<td>
					<select id="ulock2" disabled="disabled" class="easyui-combobox" name="ulock" style="width: 200px;">
						<option value="">请选择</option>
						<option value="2">是</option>
						<option value="1">否</option>
					</select>
					</td>
				</tr>
				
				<tr>
					<td>账户创建时间:</td>
					<td><input type="text" disabled="disabled" class="easyui-textbox" id="usetdate1"
						name="usetdate" /></td>
				</tr>
				<tr>
					<td>密码错误次数:</td>
					<td><input type="text" disabled="disabled" class="easyui-textbox" id="upassnum1"
						name="upassnum" /></td>
				</tr>
				<tr>
					<td>邮箱:</td>
					<td><input type="text" class="easyui-textbox" id="umail1"
						name="umail" /></td>
				</tr>
				<tr>
					<td>手机号:</td>
					<td><input type="text" class="easyui-textbox" id="uphone1"
						name="uphone" /></td>
				</tr>
				

			</table>
			<a type="button" class="easyui-linkbutton" onclick="updOK()">确定修改</a>
			<a type="button" class="easyui-linkbutton" onclick="upno()">取消</a>
		</form>
	</div>
	<div id="quanUser" class="easyui-window" title="修改用户"
		style="width: 600px; height: 400px"
		data-options="title:'编辑窗口',closed:true,modal:true">
		<form id="quanform" class="easyui-form">
			<table>
				<tr>
					<td>用户id：</td>
					<td><input type="text" disabled="disabled" class="easyui-textbox" id="uid11"
						name="uid" /></td>
				</tr>
				<tr>
					<td>权重：</td>
					<td><input type="text" class="easyui-textbox" id="ureserved11"
						name="ureserved1" /></td>
				</tr>
				<tr>
					<td>备注：</td>
					<td><input type="text" class="easyui-textbox" id="utest1"
						name="utest" /></td>
				</tr>
				

			</table>
			<a type="button" class="easyui-linkbutton" onclick="updOK1()">确定修改</a>
			<a type="button" class="easyui-linkbutton" onclick="upno1()">取消</a>
		</form>
	</div>

</body>
</html>